import { MigrationInterface, QueryRunner } from "typeorm";

export class All1746637607303 implements MigrationInterface {
    name = 'All1746637607303'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP FOREIGN KEY \`FK_12f170faa137ca64b069468025b\``);
        await queryRunner.query(`DROP INDEX \`IDX_12f170faa137ca64b069468025\` ON \`wx_user\``);
        await queryRunner.query(`DROP INDEX \`REL_12f170faa137ca64b069468025\` ON \`wx_user\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP COLUMN \`role\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP COLUMN \`doctorId\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD \`role\` tinyint NOT NULL DEFAULT '0'`);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD \`doctorId\` int NULL`);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD UNIQUE INDEX \`IDX_12f170faa137ca64b069468025\` (\`doctorId\`)`);
        await queryRunner.query(`CREATE UNIQUE INDEX \`REL_12f170faa137ca64b069468025\` ON \`wx_user\` (\`doctorId\`)`);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD CONSTRAINT \`FK_12f170faa137ca64b069468025b\` FOREIGN KEY (\`doctorId\`) REFERENCES \`doctor\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP FOREIGN KEY \`FK_12f170faa137ca64b069468025b\``);
        await queryRunner.query(`DROP INDEX \`REL_12f170faa137ca64b069468025\` ON \`wx_user\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP INDEX \`IDX_12f170faa137ca64b069468025\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP COLUMN \`doctorId\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` DROP COLUMN \`role\``);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD \`doctorId\` int NULL`);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD \`role\` tinyint NOT NULL DEFAULT '0'`);
        await queryRunner.query(`CREATE UNIQUE INDEX \`REL_12f170faa137ca64b069468025\` ON \`wx_user\` (\`doctorId\`)`);
        await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_12f170faa137ca64b069468025\` ON \`wx_user\` (\`doctorId\`)`);
        await queryRunner.query(`ALTER TABLE \`wx_user\` ADD CONSTRAINT \`FK_12f170faa137ca64b069468025b\` FOREIGN KEY (\`doctorId\`) REFERENCES \`doctor\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

}
